<?php

/**
 * IndexController
 *
 * @author    Mon Zafra <monzee at gmail>
 * @copyright (c)2009 Mon Zafra
 * @license   http://monzee.wordpress.com/license New BSD
 * @version   $Id: IndexController.php 38 2009-02-18 17:12:39Z monzee $
 */
class Admin_IndexController extends Zend_Controller_Action
{
    public function indexAction()
    {
        $aclModel = new Admin_Acl_Doctrine();

        $user = $aclModel->getUserByUsername('bazbat');
        $permissions = $aclModel->getAllPermissions();

        $this->_helper->module('admin')
            ->getAccessManager()
            ->getAclModel()
            ->setUserRoles($user->Roles);

        $resources = array();
        foreach ($permissions as $rule) {
            $res = $rule['resource_id'];
            $parts = explode('/', $res);

            $module = $parts[0];
            $controller = $parts[1];
            $action = $rule['privilege'];

            $index = $module . ' / ' . $controller . ' :: ' . $action;
            $resources[$index] = array(
                'module' => $module,
                'controller' => $controller,
                'action' => $action,
            );
        }

        $this->view->user = $user;
        $this->view->resources = $resources;
    }

    public function testAction()
    {
        $this->_helper->viewRenderer->setNoRender(true);

        $userGateway = new Admin_Zdt_Users();
        $users = $userGateway->getByUsername('quux');
        var_dump($users);
    }

}
